<?php
include(getabspath("include/commercial_invoices_settings.php"));

function DisplayMasterTableInfo_commercial_invoices($params)
{
	$detailtable=$params["detailtable"];
	$keys=$params["keys"];
	global $conn,$strTableName;
	$xt = new Xtempl();
	$oldTableName=$strTableName;
	$strTableName="commercial_invoices";

//$strSQL = "SELECT  id,  account_id,  buyer_id,  consignee_id,  notify_id,  commercial_invoice_no,  commercial_invoice_date,  customer_purchase_order_no,  bl_awb_no,  country_id,  export_date,  payment_term,  export_references,  export_route,  package_marks,  misc_charges,  certifications,  \"\" AS account_name,  \"\" AS buyer,  \"\" AS consignee,  \"\" AS notify,  proforma_invoice_id  FROM commercial_invoices  ";

$sqlHead="SELECT id,  account_id,  buyer_id,  consignee_id,  notify_id,  commercial_invoice_no,  commercial_invoice_date,  customer_purchase_order_no,  bl_awb_no,  country_id,  export_date,  payment_term,  export_references,  export_route,  package_marks,  misc_charges,  certifications,  \"\" AS account_name,  \"\" AS buyer,  \"\" AS consignee,  \"\" AS notify,  proforma_invoice_id";
$sqlFrom="FROM commercial_invoices";
$sqlWhere="";
$sqlTail="";

$where="";
$mKeys = array();
$showKeys = "";

if($detailtable=="commercial_invoice_items")
{
		$where.= GetFullFieldName("id")."=".make_db_value("id",$keys[1-1]);
	$showKeys .= " Id: ".$keys[1-1];
	$xt->assign('showKeys',$showKeys);
}
	if(!$where)
	{
		$strTableName=$oldTableName;
		return;
	}
	$str = SecuritySQL("Search");
	if(strlen($str))
		$where.=" and ".$str;

	$strWhere=whereAdd($sqlWhere,$where);
	if(strlen($strWhere))
		$strWhere=" where ".$strWhere." ";
	$strSQL= $sqlHead.' '.$sqlFrom.$strWhere.$sqlTail;

//	$strSQL=AddWhere($strSQL,$where);
	LogInfo($strSQL);
	$rs=db_query($strSQL,$conn);
	$data=db_fetch_array($rs);
	if(!$data)
	{
		$strTableName=$oldTableName;
		return;
	}
	$keylink="";
	$keylink.="&key1=".htmlspecialchars(rawurlencode(@$data["id"]));
	


//	id - 
			$value="";
				$value = ProcessLargeText(GetData($data,"id", ""),"field=id".$keylink);
			$xt->assign("id_mastervalue",$value);

//	account_id - 
			$value="";
				$value=DisplayLookupWizard("account_id",$data["account_id"],$data,$keylink,MODE_LIST);
			$xt->assign("account_id_mastervalue",$value);

//	buyer_id - 
			$value="";
				$value=DisplayLookupWizard("buyer_id",$data["buyer_id"],$data,$keylink,MODE_LIST);
			$xt->assign("buyer_id_mastervalue",$value);

//	consignee_id - 
			$value="";
				$value=DisplayLookupWizard("consignee_id",$data["consignee_id"],$data,$keylink,MODE_LIST);
			$xt->assign("consignee_id_mastervalue",$value);

//	notify_id - 
			$value="";
				$value=DisplayLookupWizard("notify_id",$data["notify_id"],$data,$keylink,MODE_LIST);
			$xt->assign("notify_id_mastervalue",$value);

//	commercial_invoice_no - 
			$value="";
				$value = ProcessLargeText(GetData($data,"commercial_invoice_no", ""),"field=commercial%5Finvoice%5Fno".$keylink);
			$xt->assign("commercial_invoice_no_mastervalue",$value);

//	commercial_invoice_date - Short Date
			$value="";
				$value = ProcessLargeText(GetData($data,"commercial_invoice_date", "Short Date"),"field=commercial%5Finvoice%5Fdate".$keylink);
			$xt->assign("commercial_invoice_date_mastervalue",$value);

//	customer_purchase_order_no - 
			$value="";
				$value = ProcessLargeText(GetData($data,"customer_purchase_order_no", ""),"field=customer%5Fpurchase%5Forder%5Fno".$keylink);
			$xt->assign("customer_purchase_order_no_mastervalue",$value);

//	bl_awb_no - 
			$value="";
				$value = ProcessLargeText(GetData($data,"bl_awb_no", ""),"field=bl%5Fawb%5Fno".$keylink);
			$xt->assign("bl_awb_no_mastervalue",$value);

//	country_id - 
			$value="";
				$value=DisplayLookupWizard("country_id",$data["country_id"],$data,$keylink,MODE_LIST);
			$xt->assign("country_id_mastervalue",$value);

//	export_date - Short Date
			$value="";
				$value = ProcessLargeText(GetData($data,"export_date", "Short Date"),"field=export%5Fdate".$keylink);
			$xt->assign("export_date_mastervalue",$value);

//	payment_term - 
			$value="";
				$value=DisplayLookupWizard("payment_term",$data["payment_term"],$data,$keylink,MODE_LIST);
			$xt->assign("payment_term_mastervalue",$value);

//	export_references - 
			$value="";
				$value = ProcessLargeText(GetData($data,"export_references", ""),"field=export%5Freferences".$keylink);
			$xt->assign("export_references_mastervalue",$value);

//	export_route - 
			$value="";
				$value = ProcessLargeText(GetData($data,"export_route", ""),"field=export%5Froute".$keylink);
			$xt->assign("export_route_mastervalue",$value);

//	package_marks - 
			$value="";
				$value = ProcessLargeText(GetData($data,"package_marks", ""),"field=package%5Fmarks".$keylink);
			$xt->assign("package_marks_mastervalue",$value);

//	misc_charges - 
			$value="";
				$value = ProcessLargeText(GetData($data,"misc_charges", ""),"field=misc%5Fcharges".$keylink);
			$xt->assign("misc_charges_mastervalue",$value);

//	certifications - 
			$value="";
				$value = ProcessLargeText(GetData($data,"certifications", ""),"field=certifications".$keylink);
			$xt->assign("certifications_mastervalue",$value);

//	account_name - HTML
			$value="";
				$value = GetData($data,"account_name", "HTML");
			$xt->assign("account_name_mastervalue",$value);

//	buyer - 
			$value="";
				$value = ProcessLargeText(GetData($data,"buyer", ""),"field=buyer".$keylink);
			$xt->assign("buyer_mastervalue",$value);

//	consignee - 
			$value="";
				$value = ProcessLargeText(GetData($data,"consignee", ""),"field=consignee".$keylink);
			$xt->assign("consignee_mastervalue",$value);

//	notify - 
			$value="";
				$value = ProcessLargeText(GetData($data,"notify", ""),"field=notify".$keylink);
			$xt->assign("notify_mastervalue",$value);

//	proforma_invoice_id - 
			$value="";
				$value=DisplayLookupWizard("proforma_invoice_id",$data["proforma_invoice_id"],$data,$keylink,MODE_LIST);
			$xt->assign("proforma_invoice_id_mastervalue",$value);
	$xt->display("commercial_invoices_masterlist.htm");
	$strTableName=$oldTableName;
}

?>